package cn.hlife.com.hlfhaemocyte;
//
//import android.app.Dialog;
//import android.content.Intent;
//import android.os.Handler;
//import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
//import android.os.Bundle;
//import android.view.View;
//import android.view.animation.AnimationUtils;
//import android.widget.ProgressBar;
//import android.widget.Toast;
//
//import com.greendaodemo.greendao.gen.DaoMaster;
//import com.greendaodemo.greendao.gen.DaoSession;
//import com.inuker.bluetooth.library.Constants;
//import com.inuker.bluetooth.library.connect.listener.BluetoothStateListener;
//import com.inuker.bluetooth.library.connect.options.BleConnectOptions;
//import com.inuker.bluetooth.library.connect.response.BleConnectResponse;
//import com.inuker.bluetooth.library.connect.response.BleNotifyResponse;
//import com.inuker.bluetooth.library.connect.response.BleWriteResponse;
//import com.inuker.bluetooth.library.model.BleGattProfile;
//
//import java.util.Date;
//import java.util.UUID;
//
//import cn.hlife.com.hlfhaemocyte.bean.MeasureEntity;
//import cn.hlife.com.hlfhaemocyte.bluetooth.ClientManager;
//import cn.hlife.com.hlfhaemocyte.measure.FragmentLinstener;
//import cn.hlife.com.hlfhaemocyte.measure.MersurePrecentor;
//import cn.hlife.com.hlfhaemocyte.measure.view.MeasureRecordDetailsActivity;
//import cn.hlife.com.hlfhaemocyte.utils.DateUtil;
//import cn.hlife.com.hlfhaemocyte.utils.DialogUtils;
//import cn.hlife.com.hlfhaemocyte.utils.HaemocyteApplication;
//import cn.hlife.com.hlfhaemocyte.utils.LogUtils;
//import cn.hlife.com.hlfhaemocyte.utils.TransformDataUtils;
//import cn.hlife.com.hlfhaemocyte.view.LoadingDialog;
//
//import static com.inuker.bluetooth.library.Constants.REQUEST_FAILED;
//import static com.inuker.bluetooth.library.Constants.REQUEST_SUCCESS;
//
public class BaseActivity extends AppCompatActivity {
//
//    private final static UUID UUID_NOTIFY =
//            UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb");
//    private final static UUID UUID_SERVICE =
//            UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb");
//    private String macAddress = "00:15:83:00:54:C3";
//    Dialog loadingDialog;
//    Handler handler=new Handler();
//
//    public  MeasureEntity measureEntity;
//    public LoadingDialog  meansureDialog;
//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        LogUtils.e("父类");
//        switchConnectStatus();
////        if(mersurePrecentor==null){
//
////        }
//    }
//    public  void  showTest(){
//        meansureDialog.show();
//    }
//    public void switchConnectStatus() {
//        if (!ClientManager.getClient().isBluetoothOpened()) {
//            ClientManager.getClient().openBluetooth();
//            Toast.makeText(this, "正在打开蓝牙", Toast.LENGTH_SHORT).show();
//            ClientManager.getClient().registerBluetoothStateListener(mBluetoothStateListener);
//            return;
//        }
//        int status = ClientManager.getClient().getConnectStatus(macAddress);
//        LogUtils.e("连接状态：" + status);
//        switch (status) {
//            case Constants.STATUS_UNKNOWN:
//                break;
//            case Constants.STATUS_DEVICE_CONNECTING:
//                break;
//            case Constants.STATUS_DEVICE_CONNECTED:
//                Toast.makeText(this, "蓝牙已经连接", Toast.LENGTH_SHORT).show();
//                notifyMeth();
//                break;
//            case Constants.STATUS_DEVICE_DISCONNECTING:
//                break;
//            case Constants.STATUS_DEVICE_DISCONNECTED:
//                connBle();
//                break;
//        }
//    }
//    public void connBle() {
//        loadingDialog = new DialogUtils().createLoadingDialog(this, "蓝牙连接中...", new DialogUtils.OnProgressView() {
//            @Override
//            public void progressOnProgressView(ProgressBar progressBar) {
//                progressBar.setVisibility(View.GONE);
//            }
//        });
//        BleConnectOptions options = new BleConnectOptions.Builder()
//                .setConnectRetry(3)   // 连接如果失败重试3次
//                .setConnectTimeout(10000)   // 连接超时30s
//                .setServiceDiscoverRetry(3)  // 发现服务如果失败重试3次
//                .setServiceDiscoverTimeout(10000)  // 发现服务超时20s
//                .build();
//        ClientManager.getClient().connect(macAddress, options, new BleConnectResponse() {
//            @Override
//            public void onResponse(int code, BleGattProfile profile) {
//                LogUtils.e("蓝牙连接返回结果：" + code);
//                handler.post(new Runnable() {
//                    @Override
//                    public void run() {
//                        loadingDialog.dismiss();
//                    }
//                });
//                if (code == REQUEST_SUCCESS) {
//                    notifyMeth();
//                }else if(code==REQUEST_FAILED){
//                    Toast.makeText(BaseActivity.this, "蓝牙连接失败", Toast.LENGTH_SHORT).show();
//                }
//            }
//        });
//    }
//
//    private final BluetoothStateListener mBluetoothStateListener = new BluetoothStateListener() {
//        @Override
//        public void onBluetoothStateChanged(boolean openOrClosed) {
//            LogUtils.e("开启蓝牙返回值-->" + openOrClosed);
//            if (openOrClosed) {
//                switchConnectStatus();
//            } else {
//                Toast.makeText(BaseActivity.this, "蓝牙已断开请检查蓝牙设备", Toast.LENGTH_SHORT).show();
//            }
//        }
//    };
//
//    public void notifyMeth() {
//        ClientManager.getClient().notify(macAddress, UUID_SERVICE, UUID_NOTIFY, mNotifyRsp);
//    }
//
//    private final BleNotifyResponse mNotifyRsp = new BleNotifyResponse() {
//        @Override
//        public void onNotify(UUID service, UUID character, byte[] value) {
//            if (service.equals(UUID_SERVICE) && character.equals(UUID_NOTIFY)) {
//                String tem = TransformDataUtils.toHex(value);
//                LogUtils.e("接收数据：" + tem);
//                if (tem.contains("bb03050100")) {
//                    stringBuffer.append(tem);
//                    LogUtils.e("测量结束-->>>" + "保存-》");
//                    handler.post(new Runnable() {
//                        @Override
//                        public void run() {
//                            meansureDialog.dismiss();
//                        }
//                    });
//                    mersurePrecentor.filtrateMeasureData(stringBuffer.toString());
//                } else if (tem.equals("bb03050101")) {
//                    stringBuffer.setLength(0);
//                    stringBuffer.append(tem);
//                    handler.post(new Runnable() {
//                        @Override
//                        public void run() {
//                            meansureDialog.show();
//                        }
//                    });
//                    LogUtils.e("测量开始-->>>");
//                }
//            }
//        }
//
//        @Override
//        public void onResponse(int code) {
//            if (code == REQUEST_SUCCESS) {
//            }
//        }
//    };
//
////    @Override
////    public void onDestroy() {
////        super.onDestroy();
//////        ClientManager.getClient().disconnect(macAddress);
//////        ClientManager.getClient().unregisterBluetoothStateListener(mBluetoothStateListener);
////    }
}
